package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueService;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private ITbClueService iTbClueService;

    /**
     * 查询线索跟进记录列表
     * @param clueId
     * @return
     */
    @Override
    public List<Map<String, Object>> listClueTrackRecord(Long clueId) {

        return  tbClueTrackRecordMapper.listClueTrackRecord(clueId);
    }

    /**
     * 新增线索跟进记录
     * @param tbClueTrackRecord
     */
    @Override
    public void addClueTrackRecord(ClueTrackRecordVo tbClueTrackRecord) {
        //获取一下当前操作用户的name  要放进create_by 字段里面
        String username = SecurityUtils.getUsername();

        tbClueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord,username);

        // 修改线索管理
        TbClue tbClue = new TbClue();
        tbClue.setName(tbClueTrackRecord.getName());
        tbClue.setAge(tbClueTrackRecord.getAge());
        tbClue.setSex(tbClueTrackRecord.getSex());
        tbClue.setWeixin(tbClueTrackRecord.getWeixin());
        tbClue.setQq(tbClueTrackRecord.getQq());
        tbClue.setSubject(tbClueTrackRecord.getSubject());
        tbClue.setLevel(tbClueTrackRecord.getLevel());

        iTbClueService.updateTbClue(tbClue);
    }
}
